﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CLinq
{
    public class CustomerQueries
    {
        public static object FinalQuery(SharedLibrary.Customer[] customers)
        {
            var results = from c in customers
                          from o in c.Orders
                          orderby c.FirstName
                          where c.FirstName.Length >= 5 && o.Product == "Milk"
                          group o by c into orders
                          select new { Name = orders.Key.FirstName + " " + orders.Key.LastName, 
                                       AverageOrder = orders.Average(o => o.Quantity) };
            return results;
        }

    }

    
}
